<?php
include_once('admin_global.php');
bn_include_lib('bn_jquery');
$theme->add_block('body');

$grid=new bn_grid;

$grid->delete->caption=$lang[17];
$grid->delete->enable=true;
$grid->delete->cssclass='button red';
$grid->header_show=true;
$grid->page_size=30;
$grid->paging->enable=true;
$grid->paging->caption=$lang[75];
$grid->paging->cssclass='button';

$cmnt=new bn_comment;

$cid=new column;
$cid->field_name='id';
$cid->hide=true;
$grid->columns->append($cid);

$cpid=new column;
$cpid->caption=$lang[78];
$cpid->field_name='pid';
$grid->columns->append($cpid);

$ctit=new column;
$ctit->caption=$lang[71];
$ctit->field_name='title';
$grid->columns->append($ctit);

$cname=new column;
$cname->caption=$lang[19];
$cname->field_name='name';
$grid->columns->append($cname);

$cip=new column;
$cip->caption=$lang[20];
$cip->field_name='ip';
$grid->columns->append($cip);

$ccmnt=new column;
$ccmnt->caption=$lang[21];
$ccmnt->field_name='comment';
$ccmnt->editable=true;
$grid->columns->append($ccmnt);

$cmail=new column;
$cmail->caption=$lang[22];
$cmail->field_name='mail';
$grid->columns->append($cmail);

$cdate=new column;
$cdate->caption=$lang[23];
$cdate->field_name='date';
$cdate->mask='per_date';
$grid->columns->append($cdate);

$cshow=new column;
$cshow->caption=$lang[24];
$cshow->template='<input type="submit" name="status" id="status" class="button" value="<%status%>"/>';
$grid->columns->append($cshow);

function per_date($date)
{
    if(isset($date))
    return bndate('Y/n/d',$date);
    else
    return '';
}

$theme->add_script($grid->command_script('#search_div'));

$theme->add_script(jquery_element('#status','click','
var id=$(this).closest("tr").find("td :eq(0)").html();
$.post(window.location.href,{cmd:"state",id:id,val:$(this).val(),value:$("#search_txt").val(),column:$("#type").val()},function(data){
$("#show").html(data);
});
'));

$theme->add_script(jquery_element('#search','click','
$.post(window.location.href,{cmd:"search",value:$("#search_txt").val(),column:$("#type").val()},function(data){
$("#show").html(data);
});
'));

if(isset($_POST['cmd']))
{
    extract($_POST);
    if($cmd=='delete')
    $cmnt->delete($id);
    
    if($cmd=='state')
    {
        if($val=='disable')
        $val='enable';
        else
        $val='disable';
        $cmnt->update('status',$val,$id);
    }
    
    if($cmd=='update_edit')
    {
        $cmnt->update($col,$val,$id);
        die;
    }
    die($grid->show($cmnt->select_comments($column,$value)->fetch()));
}
?>

<div id="search_div">
<label><?= $lang[26]?></label>
<select size="1" name="type" id="type" class="select">
	<option value="name">name</option>
	<option value="ip">ip</option>
	<option value="mail">mail</option>
	<option value="date">date</option>
	<option value="pid">postid</option>
</select>
<input type="text" size="35" autocomplete="on" name="search_txt" id="search_txt" class="input-text"/>
<input type="submit" name="search" id="search" class="button" value="<?= $lang[26]?>"/>
<div id="show">
<?php
	echo $grid->show($cmnt->select_comments()->fetch());
?>
</div>
</div>
<?php
$theme->render();
?>